﻿$(function () {
    $('.select2').select2()

    $('.select2bs4').select2({
        theme: 'bootstrap4'
    })
});

function FunSelectItem(obj) {
    var purchaseOrderId = obj.options[obj.selectedIndex].value;
    if (purchaseOrderId == '' || purchaseOrderId == undefined) return;
    AjaxRequest(purchaseOrderId);
}

function AjaxRequest(purchaseOrderId) {
    var result;
    $.ajax({
        type: "POST",
        async: false,
        cache: false,
        url: "/PurchaseOrder/GetPurchaseOrderById",
        data: { purchaseOrderId: purchaseOrderId },
        dataType: "json",
        success: function (data) {
            result = data;
        }
    });

    result = JSON.stringify(result);
    var model = JSON.parse(result);
    
    var html = '<tr>';
    if (model == null || model == undefined) {
        html = html + '<td align="center">无数据！</td>';
    }
    else {
        html = html + ' <td>' + model.purchaseOrderNo + ' </td>'
            + ' <td>' + model.itemCode + ' </td>'
            + ' <td>' + model.itemName + ' </td>'
            + ' <td>' + model.reviewBy + ' </td>'
            + ' <td>' + ConverDate(model.reviewDate) + ' </td>'
            + ' <td>' + model.reviewStateString + ' </td>'
            + ' <td>' + model.purchaseCount + ' </td>'
            + ' <td>' + model.purchaseOrderTypeString + ' </td>'
            + ' <td>' + model.createBy + ' </td>'
            + ' <td>' + ConverDate(model.createDate) + ' </td>'
            + ' <td>' + model.address + ' </td>'
            + ' <td>' + model.remark + ' </td>'
    }
    html = html + ' </tr>';

    $('.tbody').html(html);
}

function ConverDate(str) {
    var oldTime = (new Date(str.toString())).getTime();
    da = new Date(oldTime);
    var year = da.getFullYear() + '年';
    var month = da.getMonth() + 1 + '月';
    var date = da.getDate() + '日';
    return year + month + date;
}